package com.example.admin.SQLite.dao;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.example.admin.SQLite.SqLiteOpenHelper;
import com.example.admin.SQLite.User;
import com.example.admin.SQLite.admin;

import java.util.ArrayList;

import static com.example.admin.SQLite.SqLiteOpenHelper.TABLE_ADMIN;
import static com.example.admin.SQLite.SqLiteOpenHelper.TABLE_USER;

public class AdminDao {
    SqLiteOpenHelper dbHelper;
    private static final String KEY_ID = "id";

    public AdminDao(Context context) {
        dbHelper = new SqLiteOpenHelper(context);
    }
    public ArrayList<admin> getUserList() {
        SQLiteDatabase db = dbHelper.getSqlite();
        Cursor cursor = db.rawQuery("SELECT * FROM " + TABLE_ADMIN, null);

        ArrayList<admin> arrContacts = new ArrayList<>();

        while (cursor.moveToNext()) {
            admin model = new admin();
            model.id = cursor.getInt(0);
            model.adminName = cursor.getString(1);
            model.adminPassword = cursor.getString(2);

            arrContacts.add(model);

        }
        return arrContacts;
    }
    public void updateUserPass(int id,String pass){

        SQLiteDatabase database =dbHelper.getSqlite();

        ContentValues cv = new ContentValues();
        cv.put("adminPassword",pass);

        database.update(TABLE_ADMIN,cv,KEY_ID+" = "+ id,null);
    }

    public void addUserData(admin bean){
        SQLiteDatabase db = dbHelper.getSqlite();
        Log.e("发的地方", "addUserData: "+bean.toString() );
        ContentValues values = new ContentValues();
        values.put("adminName",bean.adminName);
        values.put("adminPassword",bean.adminPassword);
        db.insert(TABLE_ADMIN, null,values);
    }
}
